//
//  HMTabBatController.swift
//  swift微博项目
//
//  Created by huodian on 16/9/22.
//  Copyright © 2016年 huodian. All rights reserved.
//

import UIKit

class HMTabBatController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let hmresign = HMMaintabbar()
        
        
        hmresign.closuer = {[unowned self] in
            
            print("按钮被点击了")
            
            print(self)
            
        }
        
        
        self.setValue(hmresign, forKey: "tabBar")
        
      // addChildViewController()
        
       
        loadTheViewcontroller()
        
    }
    
    func loadTheViewcontroller()
    {
        
        print("进来了没")
        self.addChildviewcontrollerToMain(title: "首页", image: "tabbar_home", vc: HMHomeViewController())
        

        self.addChildviewcontrollerToMain(title: "信息", image:"tabbar_message_center", vc: HMMessageViewController())
        
         self.addChildviewcontrollerToMain(title: "发现", image: "tabbar_discover", vc: HMDIscoverViewController())
        
        self.addChildviewcontrollerToMain(title: "我", image: "tabbar_profile", vc: HMMeViewController())
        
       
        
        
        
    }

    func addChildviewcontrollerToMain(title:String,image:String,vc:UIViewController){
        
        
        vc.navigationItem.title = title
        
        vc.tabBarItem.title = title
        
        vc.tabBarItem.image = UIImage(named: image)
        
        vc.tabBarItem.selectedImage = UIImage(named: image + "_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal).withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orange], for: .selected)
        
        
        vc.tabBarItem.imageInsets = UIEdgeInsetsMake(3, 0, -3, 0)
        
        
        let nav = HMNavgationController(rootViewController:vc)
        
        
      
        
        
   
        
        
         self.addChildViewController(nav) 
    }

    
    
    
}
